﻿namespace VehicleRental.API.Models
{
    using System;
    using System.Runtime.Serialization;
    using VehicleRental.Models;

    [DataContract]
    public class VehicleModel
    {
        [DataMember(Name="id")]
        public int Id { get; set; }

        [DataMember(Name = "rentedDate")]
        public DateTime? RentedDate { get; set; }

        [DataMember(Name = "year")]
        public int Year { get; set; } // year of manufacturing

        [DataMember(Name = "manufacturer")]
        public string Manufacturer { get; set; }

        [DataMember(Name = "model")]
        public string Model { get; set; }

        [DataMember(Name = "vehicleType")]
        public VehicleType Type { get; set; }

        [DataMember(Name = "rentedPeriod")]
        public int RentedPeriod { get; set; } // rented time in hours

        [DataMember(Name = "pricePerHour")]
        public decimal PricePerHour { get; set; }

        [DataMember(Name = "isRented")]
        public bool IsRented { get; set; }
        
        [DataMember(Name = "vehicleFee")]
        public decimal VehicleFee { get; set; } // get fee from user if car is not returned before end period

        [DataMember(Name = "placeId")]
        public int PlaceId { get; set; }

        [DataMember(Name="imageSource")]
        public string ImageSource { get; set; }

        public static VehicleModel Parse(Vehicle currentVehicle)
        {
            return new VehicleModel()
            {
                Id = currentVehicle.Id,
                IsRented = currentVehicle.IsRented,
                Manufacturer = currentVehicle.Manufacturer,
                Model = currentVehicle.Model,
                PlaceId = currentVehicle.Place.Id,
                PricePerHour = currentVehicle.PricePerHour,
                RentedDate = currentVehicle.RentedDate,
                RentedPeriod = currentVehicle.RentedPeriod,
                Type = currentVehicle.Type,
                VehicleFee = currentVehicle.Fee,
                Year = currentVehicle.Year,
                ImageSource = currentVehicle.ImageSource
            };
        }


        public static Vehicle Parse(VehicleModel currentVehicle)
        {
            return new Vehicle()
            {
                Year = currentVehicle.Year,
                Model = currentVehicle.Model,
                Manufacturer = currentVehicle.Manufacturer,
                ImageSource = currentVehicle.ImageSource,
                PricePerHour = currentVehicle.PricePerHour,
                Fee = currentVehicle.VehicleFee,
                Type = currentVehicle.Type
            };
        }
    }
}
